var app = getApp()

Page({
  data: {
    dataList: ["离线", "核心堵转", "缺料报警", "补料提醒", "补料", "核心堵转", "缺料报警", "补料提醒", "补料"],
    status: ['订单收益', '订单手续费', '自动提现', '提现手续费'],
    size: 10,
    loading: true,
    key: "",
    isFresh: false,
  },
  onLoad: function () {
    this.setData({
      sh: app.globalData.screenHeight,
      sw: app.globalData.screenWidth
    })
    this.getAccountList();
  },

  // 获取对账列表
  getAccountList:function(){
    var key = this.data.key
    var size = this.data.size
    var baseUrl = app.globalData.baseUrl
    var token = app.globalData.token
    var that = this

    wx.request({
      url: 'https://web.api.sdaascloud.com/web/personAcc/getPersonAccList?key='+key+'&page=0&size='+size,
      header: {
        'AUTHORIZATION': token
      },
      success: function (res) {
        if (res.data.code == 60006) {
          verify.clearAll()
        } else if (res.data.code == 200) {
          // console.log("accountList = ",res.data.data.content)
          var accountList = res.data.data.content
          var nameList = []
          for (var i = 0; i < res.data.data.content.length;i++){
            if (accountList[i].orderType =="ORDER_EARNINGS"){
              nameList[i] = "订单收益"
            } else if (accountList[i].orderType == "SERVICE_CHARGE"){
              nameList[i] = "订单手续费"
            } else if (accountList[i].orderType == "WITHDRAW") {
              nameList[i] = "自动提现"
            } else if (accountList[i].orderType == "WITHDRAW_CHARGE") {
              nameList[i] = "提现手续费"
            }
          }

          var totalElements = res.data.data.totalElements
          var loading = false
          if (totalElements > size) {
            loading = true
          }
          // console.log("nameList = ",nameList)
          that.setData({
            accountList: accountList,
            nameList:nameList,
            totalElements: totalElements,
            loading: loading,
            isFresh: false
          })
        } else {
          wx.showModal({
            title: '操作失败',
            content: res.data.message,
          })
        }
      }
    })
  },

  menu: function (res) {
    console.log(res.detail.value)
    console.log(this.data.status[res.detail.value])
    
  },
  date: function (res) {
    console.log(res.detail.value)
  },

  onReachBottom: function () {
    console.log("触底")
    var size = this.data.size * 1 + 10
    var loading = this.data.loading
    var totalElements = this.data.totalElements
    this.setData({
      isFresh: true
    })
    if (size - 10 > totalElements) {
      this.setData({
        loading: false
      })
    } else {
      this.setData({
        size: size
      })
      this.getAccountList();
    }
  }

})
